import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'

import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { ENTRY } from '../../../enter';
import { txsInfoItemsEntity, blockEntity, txsInBlockEntity,txInfoEntity, txRecipyEntity } from './message-details.entity';

@Injectable({
  providedIn: 'root'
})
export class MessageDetailsService {
  private headers: HttpHeaders;
  constructor(private http: HttpClient) {
    this.headers = new HttpHeaders();
    this.headers.set('Content-Type', 'application/json');
  }
  private blockNumberBaseUrl = '/appapi/WeBASE-Front/1/web3/blockNumber';
  private blockDetailsBaseUrl = '/appapi/WeBASE-Front/1/web3/blockByNumber/';
  private TxInfoBaseUrl = '/appapi/WeBASE-Front/1/web3/transaction/';
  private TxRecipyBaseUrl = '/appapi/WeBASE-Front/1/web3/transactionReceipt/';
  public getBlockNumber(): Observable<number> {
    return this.http.get<number>(this.blockNumberBaseUrl, {
      headers: this.headers
    });
  }
  public getBlockDetails(index: number): Observable<blockEntity> {
    return this.http.get<blockEntity>(this.blockDetailsBaseUrl + String(index), {
      headers: this.headers
    });
  }
  public getTxInfo(hash: string): Observable<txInfoEntity> {
    return this.http.get<txInfoEntity>(this.TxInfoBaseUrl + hash, {
      headers: this.headers
    });
  }

  public getTxRecipy(hash: string): Observable<txRecipyEntity> {
    return this.http.get<txRecipyEntity>(this.TxRecipyBaseUrl + hash, {
      headers: this.headers
    });
  }

}
